package validation

import (
	"github.com/go-playground/validator/v10"
	"regexp"
)

func PhoneValidator(f validator.FieldLevel) bool {
	if value, ok := f.Field().Interface().(string); ok {
		if len(value) == 0 {
			return true
		}
		regular := "^(13[0-9]|14[01456879]|15[0-35-9]|16[124567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$"
		reg := regexp.MustCompile(regular)
		return reg.MatchString(value)
	}
	return false
}

func EmailValidator(f validator.FieldLevel) bool {
	if value, ok := f.Field().Interface().(string); ok {
		if len(value) == 0 {
			return true
		}
		regular := `\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*`
		reg := regexp.MustCompile(regular)
		return reg.MatchString(value)
	}
	return false
}
